package net.oschina.names4j.core.constants;

import net.oschina.names4j.core.Firstname;

import java.util.Random;

/**
 * @Author Zhoufan [https://github.com/fantaga].
 * @Date 2016/12/26
 * @Description:
 */
public class FirstnameDictionary {

	private final static String singleFirstnames[] = {"李","王","张","刘","陈","杨","赵","黄","周","吴","万","徐","孙","胡","朱","高","林","何","郭","马","万","罗","梁","宋","郑","谢","韩","唐","冯","于","董","萧","程","曹","袁","邓","许","傅","沈","曾","彭","吕","苏","卢","蒋","蔡","魏","贾","丁","薛","叶","阎","余","潘","杜","戴","夏","钟","汪","田","任","姜","范","方","石","姚","谭","廖","邹","熊","金","陆","郝","孔","白","崔","康","毛","邱","秦","江","史","顾","侯","邵","孟","龙","万","段","雷","钱","汤","尹","易","黎","常","武","乔","贺","赖","龚","文"};

	private final static String complexFirstnames[] = {"万俟","司马","上官","欧阳","夏侯","诸葛","闻人","东方","赫连","皇甫","尉迟","公羊","澹台","公冶","宗政","濮阳","淳于","单于","太叔","申屠","公孙","仲孙","轩辕","令狐","锺离","宇文","长孙","慕容","鲜于","闾丘","司徒","司空","丌官","司寇","子车","颛孙","端木","巫马","公西","漆雕","乐正","壤驷","公良","拓拔","夹谷","宰父","谷梁","段干","百里","东郭","南门","呼延","羊舌","微生","梁丘","左丘","东门","西门","南宫","子书"};

	public static final int ssize = singleFirstnames.length;

	public static final int csize = complexFirstnames.length;

	private final static Random rcomplex= new Random(System.nanoTime());

	private final static Random rsingle= new Random(System.nanoTime());

	private FirstnameDictionary(){
	}

	public static String getComplexFirstname(){
		return complexFirstnames[rcomplex.nextInt(csize)];
	}

	public static String getSingleFirstname(){
		return singleFirstnames[rsingle.nextInt(ssize)];
	}
	public static String getFirstname(String firstname){
		if(contains(firstname))
			return firstname;
		throw  new RuntimeException("\"" + firstname + "\"" + " 不存在百家姓中");
	}

	public static boolean contains(Firstname firstName){

		final boolean isExist;
		final String firstname = firstName.name();
		for(String fname : singleFirstnames)
		{
			if(fname.equals(firstname))
				return true;
		}
		for(String fname : complexFirstnames)
		{
			if(fname.equals(firstname))
				return true;
		}
		return false;
	}
	public static boolean contains(String firstName){

		final boolean isExist;

		for(String fname : singleFirstnames)
		{
			if(fname.equals(firstName))
				return true;
		}
		for(String fname : complexFirstnames)
		{
			if(fname.equals(firstName))
				return true;
		}
		return false;
	}
}
